<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '已过期患者列表';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="patient-index">

    <h1 style="margin-bottom: 1em;"><?= Html::encode($this->title) ?></h1>

    <p style="display: none;">
        <?= Html::a('创建 患者预约', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <div style="margin: 1em 0;">
        <a href="javascript:show_search_form();void(0)" class="btn btn-primary btn-lg" style="width:120px;"> 查 询 器 </a>

        <div class="btn-group">
            <a href="<?= Url::toRoute('patient/expirydate') ?>" class="btn btn-info search_date" style="width:80px;">刷 新</a>
            <a href="javascript:search_date(this, 'createtime', 'yestoday');void(0)" class="btn btn-default search_date" style="color:#337ab7">昨日录单</a>
            <a href="javascript:search_date(this, 'createtime', 'today');void(0)" class="btn btn-default search_date" style="color:#d9534f">今日录单</a>
        </div>

        <div class="btn-group" role="group">
            <a href="javascript:search_sex(this, 'sex', '男');void(0)" class="btn btn-default search_sex" style="color:#337ab7">男</a>
            <a href="javascript:search_sex(this, 'sex', '女');void(0)" class="btn btn-default search_sex" style="color:#d9534f">女</a>
        </div>

        <div class="btn-group" role="group">
            <a href="javascript:search_type(this, 'record');void(0)" class="btn btn-default search_type" style="color:#337ab7">录单过期</a>
            <a href="javascript:search_type(this, 'order_time');void(0)" class="btn btn-default search_type" style="color:#d9534f">预约过期</a>
        </div>

        <div class="btn-group" style="width:360px;">
            <div class="input-group">
                <div class="input-group-btn">
                    <select id="search_like_attr" class="form-control" style="width:110px;">
                        <option value="name" selected>姓名</option>
                        <option value="telphone">电话</option>
                        <option value="forever_id">永久身份</option>
                    </select>
                </div>
                <input id="search_like_value" type="text" class="form-control" style="border-left:none" />
                <div class="input-group-btn">
                    <a href="javascript:search_like();void(0)" class="btn btn-success">模糊搜索</a>
                </div>
            </div>
        </div>

    </div>

    <?= $this->render('review_form', ['model' => new app\models\Recall()]) ?>

    <?= $this->render('search_form', [
        'search' => $search,
        'workgroup_array' => $workgroup_array,
        'comeway_array' => $comeway_array,
        'communication_array' => $communication_array,
        'user_array' => $user_array,
        'disease_array' => $disease_array,
        'doctor_array' => $doctor_array,
        'status_array' => $status_array
    ]) ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            //['class' => 'yii\grid\SerialColumn'],

            //'id',
            'name',
            'age',
            'sex',
            //'address',
            ['label' => '电话', 'value' => 'filter_phone'],
            ['label' => '科室', 'attribute' => 'department_id', 'value' => 'department_name'],
            ['label' => '病种', 'attribute' => 'disease_ids', 'value' => 'disease_name'],
            'order_number',
            'istoday',
            // 'qq',
            // 'wechat',
            'workgroup',
            // 'communication_id',
            // 'comeway_id',
            ['label' => '咨询人员', 'attribute' => 'user_id', 'value' => 'username'],
            ['label' => '录单时间/最后回访时间', 'attribute' => 'last_recall_time', 'value' => 'last_recall_time'],
            'status',
            // 'order_doctor_id',
            'order_time',
            'forever_id',
            'keyword',
            //'recall_ids',
            //'condition_log:ntext',
            //'talk_log:ntext',
            //'edit_log:ntext',

            [
                'class' => 'yii\grid\ActionColumn', 'template' => '{view} {update} {review}', 'buttons' => [
                    'review' => function ($url, $model, $key) {
                        return Html::tag('i', '', ['class' => "glyphicon glyphicon-phone-alt", 'title' => '回访', 'onclick' => 'patient_review(\'' . $model->name . '\', ' . $model->id . ')']);
                    }
                ]
            ],
        ],
    ]); ?>


</div>

<script type="text/javascript">
    function init_search() {
        window.yyh_search = {
            createtime: null,
            order_time: null,
            arrive_time: null,
            expiry_type: null,
            like: {
                sex: null,
                name: null,
                telphone: null,
                forever_id: null
            }
        };
    }

    function search_to() {
        var first_href = "<?= Url::toRoute('patient/expirydate') ?>";
        for (var index in window.yyh_search) {
            if (index != 'like' && window.yyh_search[index] != null) {
                first_href += '&search[' + index + ']=' + window.yyh_search[index];
            }
        }

        for (var index in window.yyh_search.like) {
            if (window.yyh_search.like[index] != null) {
                first_href += '&search[' + index + ']=' + window.yyh_search.like[index];
            }
        }
        window.location.href = first_href;
    }

    function search_date(obj, attr, value) {
        init_search();
        window.yyh_search[attr] = value;
        search_to();
    }

    function search_sex(obj, attr, value) {
        init_search();
        window.yyh_search[attr] = value;
        search_to();
    }

    function search_type(obj, value) {
        init_search();
        window.yyh_search['expiry_type'] = value;
        search_to();
    }

    function search_like() {
        init_search();
        var attr = $('#search_like_attr').val();
        window.yyh_search.like[attr] = $('#search_like_value').val().replace(/(^\s*)|(\s*$)/g, "");
        search_to();
    }

    function key_enter() {
        $('#search_like_value').bind('keypress', function(event) {
            if (event.keyCode == "13") {
                search_like();
            }
        });
    }
    window.setTimeout("init_search();key_enter()", 500);
</script>